<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="120px">

      <el-form-item label="用户姓名" >
        <el-input
          style="width: 130px;"
          v-model="queryParams.name"
          placeholder="请输入用户姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="床号" >
        <el-input
          style="width: 130px;"
          v-model="queryParams.num"
          placeholder="请输入床号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="病区" >
        <el-input
          style="width: 130px;"
          v-model="queryParams.ward"
          placeholder="请输入病区"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>


      <el-form-item label="否完善手术信息" prop="userSex">
        <el-select v-model="queryParams.operation" placeholder="请选择是否完善手术信息" clearable             style="width: 130px;">
          <el-option

            label="-请选择-"
            value=""
          />
          <el-option

            label="是"
            value="0"
          />
          <el-option

            label="否"
            value="1"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="否完善出院信息" >
        <el-select v-model="queryParams.discharge" placeholder="请选择是否完善出院信息" clearable              style="width: 130px;">
          <el-option
            label="-请选择-"
            value=""
          />
          <el-option

            label="是"
            value="0"
          />
          <el-option

            label="否"
            value="1"
          />
        </el-select>
      </el-form-item>
      <!-- <el-form-item label="用户昵称" prop="userNick">
        <el-input
          v-model="queryParams.userNick"
          placeholder="请输入用户昵称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="用户性别" prop="userSex">
        <el-select v-model="queryParams.userSex" placeholder="请选择用户性别" clearable>
          <el-option
            v-for="dict in dict.type.sys_user_sex"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item> -->
      <!-- <el-form-item label="用户年龄" prop="userAge">
        <el-input
          v-model="queryParams.userAge"
          placeholder="请输入用户年龄"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>



    <el-table v-loading="loading" :data="infoList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center"/>
      <el-table-column label="id"  width="70"  align="center" prop="id" :show-overflow-tooltip='true'/>
      <el-table-column label="病区" align="center" prop="ward"/>
      <el-table-column label="床号" align="center" prop="num"/>
      <el-table-column label="姓名" align="center" prop="name"/>

      <el-table-column label="入院日期" align="center" prop="admissionTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.admissionTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="是否完善手术信息" align="center" >
      <template slot-scope="scope">
        <span>{{scope.row.operationTime!=""?"是":"否"}}</span>
      </template>
      </el-table-column>
      <el-table-column label="是否完善出院信息" align="center" >
      <template slot-scope="scope">

        <span>{{scope.row.dischargeTime!=""?"是":"否"}}</span>
      </template>
      </el-table-column>
  <!--    <el-table-column label="注册时间" align="center" prop="createTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>-->

      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['user:info:edit']"
          >查看详情
          </el-button>



        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <el-drawer

      style="width: 145%"
      :visible.sync="drawer"
      :direction="direction"

    >


      <div class="cp_form_header">
        <el-form ref="form" :model="form" :rules="rules" size="small" label-width="150px" :inline="true" width="600px">

          <span>基础信息</span>
          <el-divider></el-divider>

          <div class="cp_form_item">

            <el-form-item label="头像">
              <el-image class="medica_img"
                        :src="form.url" style="width: 200px;"></el-image>
            </el-form-item>
           <!-- <el-form-item label="用户昵称">
              <el-input v-model="form.nickName"  :readonly="true"style="width: 200px;"/>
            </el-form-item>
-->

            <el-form-item label="用户昵称:">
              <div  style="width: 200px;"> {{form.nickName}}</div>
            </el-form-item>
          </div>

          <div class="cp_form_item">

            <el-form-item label="姓名:">
              <div  style="width: 200px;"> {{form.name}}</div>
            </el-form-item>
            <el-form-item label="手机号:">
              <div  style="width: 200px;"> {{form.phone}}</div>
            </el-form-item>

          </div>
          <div class="cp_form_item">
            <el-form-item label="性别:">
              <div  style="width: 200px;"> {{form.sex}}</div>
            </el-form-item>
            <el-form-item label="年龄:">
              <div  style="width: 200px;"> {{form.age>=0?form.age:"-"}}</div>
            </el-form-item>


          </div>


          <div class="cp_form_item">

            <el-form-item label="注册时间:">
              <div  style="width: 200px;">{{ parseTime(form.userCreateTime, '{y}-{m}-{d}') }} </div>
            </el-form-item>
            <el-form-item label="用户提交信息时间:">
              <div  style="width: 200px;">{{ parseTime(form.createTime, '{y}-{m}-{d}') !=""?form.createTime:"-"}} </div>

            </el-form-item>

          </div>
          <el-divider></el-divider>
          <span>用户提交信息</span>
          <el-divider></el-divider>

          <div class="cp_form_item">

            <el-form-item label="入院日期:">

              <div  style="width: 200px;"> {{form.admissionTime}}</div>
           <!--   <el-date-picker
                v-model="form.admissionTime"
                type="date"
                value-format="yyyy-MM-dd"
                style="width: 200px;"
                placeholder="选择日期">
              </el-date-picker>-->

            </el-form-item>


          </div>

          <div class="cp_form_item">
            <el-form-item label="床号:">
              <div  style="width: 200px;"> {{form.num}}</div>
             <!-- <el-input v-model="form.num" style="width: 200px;"/>-->
            </el-form-item>
            <el-form-item label="病区:">
              <div  style="width: 200px;"> {{form.ward}}</div>
        <!--      <el-input v-model="form.ward" style="width: 200px;"/>-->
            </el-form-item>
          </div>

          <div class="cp_form_item">
            <el-form-item label="诊断:">
              <div  style="width: 200px;"> {{form.diagnosis}}</div>
         <!--     <el-input v-model="form.diagnosis" style="width: 200px;"/>-->
            </el-form-item>

          </div>

          <div class="cp_form_item">

            <el-form-item label="主管医生:">
              <div  style="width: 200px;"> {{form.chiefPhysician}}</div>
           <!--   <el-input v-model="form.chiefPhysician" style="width: 200px;"/>-->
            </el-form-item>
            <el-form-item label="责任护士:">
              <div  style="width: 200px;"> {{form.nurse}}</div>
           <!--   <el-input v-model="form.nurse" style="width: 200px;"/>-->
            </el-form-item>
          </div>
          <el-divider></el-divider>
          <span>医护录入信息</span>
          <el-divider></el-divider>

          <div class="cp_form_item">

            <el-form-item label="病种:">
         <!--     <el-input v-model="form.disease" style="width: 200px;"/>-->

              <el-select v-model="form.disease" placeholder="请选择病种" clearable              style="width: 130px;">

                <el-option

                  label="上肢"
                  value="上肢"
                />
                <el-option

                  label="下肢"
                  value="下肢"
                />
              </el-select>

            </el-form-item>
            <el-form-item label="手术方式:">
              <el-input v-model="form.operation" style="width: 200px;"/>
            </el-form-item>
          </div>

          <div class="cp_form_item">

            <el-form-item label="手术时间:">

              <el-date-picker
                v-model="form.operationTime"
                type="date"
                style="width: 200px;"
                value-format="yyyy-MM-dd"
                placeholder="选择日期">
              </el-date-picker>

            </el-form-item>
            <el-form-item label="出院时间:">
              <el-date-picker
                v-model="form.dischargeTime"
                type="date"
                value-format="yyyy-MM-dd"
                style="width: 200px;"
                placeholder="选择日期">
              </el-date-picker>

            </el-form-item>
          </div>


        </el-form>

        <div slot="footer" class="dialog-footer">
      <!--    <el-button  @click="doCancel">返回</el-button>-->
          <el-button type="primary" @click="submitForm">保存</el-button>

        </div>








      </div>



    </el-drawer>



  </div>
</template>

<script>
  import {listInfo, getInfo, delInfo, addInfo, updateInfo} from "@/api/user/hospitalization";

  export default {
    name: "Info",
    dicts: ['sys_user_sex'],
    data() {
      return {
        drawer: false,
        direction: 'ltr',
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 用户信息表格数据
        infoList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          name: null,
          num: null,
          ward: null,
          operation: null,
          discharge: null,
        },
        // 表单参数
        form: {},
        // 表单校验
        rules: {}
      };
    },
    created() {
      this.getList();
    },
    methods: {
      /** 查询用户信息列表 */
      getList() {
        this.loading = true;
        listInfo(this.queryParams).then(response => {
          this.infoList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.form = {
          id: null,
          nickName: null,
          registrationTime: null,
          createTime: null,
          admissionTime: null,
          num: null,
          ward: null,
          diagnosis: null,
          chiefPhysician: null,
          nurse: null,
          disease: null,
          operation: null,
          operationTime: null,
          dischargeTime: null,
          openId: null,
          url: null,
          userId: null,
          phone: null,
          sex: null,
          age: null
        };
        this.resetForm("form");
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.id)
        this.single = selection.length !== 1
        this.multiple = !selection.length
      },
      /** 新增按钮操作 */
      handleAdd() {
        this.reset();
        this.open = true;
        this.title = "添加用户信息";
      },

      handleUpdatedddd(){
        this.drawer = true
      },
      /** 修改按钮操作 */
   /*   handleUpdate(row) {
debugger

      },*/

      handleUpdate(row) {
        this.drawer = true
        this.reset();

        this.form = row;
      /*  const id = row.id || this.ids
        getInfo(id).then(response => {
          this.form = response.data;
          this.open = true;
          this.title = "修改用户信息";
        });*/
      },
      /** 提交按钮 */
      submitForm() {
        this.$refs["form"].validate(valid => {
          if (valid) {
            if (this.form.id != null) {
              debugger

              console.log(this.form)
              updateInfo(this.form).then(response => {
                debugger
                this.$modal.msgSuccess("修改成功");
                this.drawer = false
                this.getList();
              });
            } else {

              addInfo(this.form).then(response => {
                this.$modal.msgSuccess("新增成功");
                this.drawer = false
                this.getList();
              });
            }
          }
        });
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const ids = row.id || this.ids;
        this.$modal.confirm('是否确认删除用户信息编号为"' + ids + '"的数据项？').then(function () {
          return delInfo(ids);
        }).then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        }).catch(() => {
        });
      },
      /** 导出按钮操作 */
      handleExport() {
        this.download('user/info/export', {
          ...this.queryParams
        }, `info_${new Date().getTime()}.xlsx`)
      }
    }
  };
</script>
<style rel="stylesheet/scss" lang="scss" scoped>


  .cp_form_header {
    padding: 10px 20px;

    /*.cp_form_item {
      padding: 10px;
    }*/
  }
</style>
